<?php
function displayPage()
{
	if (get('source') == 'null')
	{
		$linkBack = INDEX.get('pages');
		$source = '';
		$buttonDelete = '';
	}
	else
	{
		$linkBack = 'widget.php?page=blog&name='.searchContentFor(get('id'), 'contName').'&pages='.get('source');
		$source = '&source='.get('source');
		$buttonDelete = '<form method="POST" action="widget.php?id='.get('id').'&page=content&pages='.get('pages').$source.'">
		<input type="hidden" name="delThis" value="'.get('id').'" />		
		<input type="submit" class="buttons" value="Delete Entry" /></form>
		';
	}
	
	if (post('updateNow')!= 'null')
	{
		if (post('contentText') == '<p></p>' || post('contentText') == '')
		{
			$stuff = '
			<div id="container">
				<div id="header">
				Status for: '.searchContentFor(post('updateNow'), 'title').'
				</div>
				<div id="confirmationText">
					You have entered a blank entry on this element\'s contents. Doing so will provide potential editing problems. Text saved this way will be difficult to recover. If you have problems and you wish to inquire us regarding this matter, email us at <a href="mailto:development@clickmediaph.com">development@clickmediaph.com</a>. <br />Do you still want to continue?
				<br /><br />
				<form method="POST" action="widget.php?id='.get('id').'&page=content&pages='.get('pages').$source.'">
					<input type="hidden" name="updateNow" value="'.post('updateNow').'" />
					<input type="hidden" name="title" value="'.post('title').'" id="titleForm"/>
					<input type="hidden" name="contentText" value="<p>&nbsp;&nbsp;&nbsp;</p>" />
					<div id="buttonDivs">
						<input type="submit" class="buttons" value="Yes" />
						<input type="button" class="buttons" value="No" title="index.php?id='.get('id').'&page=content&id='.post('updateNow').'&pages='.get('pages').$source.'" onclick="'.jsGo().'"/>
					</div>
				</form>
				</div>
				<input type="button" class="buttons" title="'.$linkBack.'" value="Close" onclick="'.jsClose().'" />				
			</div>
			';
			
		}
		else
		{
			$result = updateContent(post('updateNow'), post('contentText'), post('title'));
			$stuff = '
			<div id="container">
				<div id="header">
				Status for: '.searchContentFor(post('updateNow'), 'title').'
				</div>
				<div id="confirmationText">
					'.$result['queryStatus'].'<br />The content data for this element has been updated today '.getDateNow().'.
				</div>
				<div style="text-align: center;">
				
				<input type="button" class="buttons" title="'.$linkBack.'" value="Close" onclick="'.jsClose().'" />
				</div>
			</div>
			';
		}
		
		//$result['queryStatus'] = 'testing. No SQL has been done';
	}
	
	else if (post('delThis') != 'null')
	{
		
		$stuff = '
		<div id="container">
			<div id="header">
			Status:
			</div>
			<div id="confirmationText">
				The content data for this element has been deleted today '.getDateNow().'.
			</div>
			<div style="text-align: center;">
			<input type="button" class="buttons" title="'.$linkBack.'" value="Close" onclick="'.jsClose().'" />
			</div>
		</div>
		';
		$result = SQLDelete ('site_content', 'contentID='.get('id'));
	}
	else
	{
		$stuff ='
		<div id="container">
			<div id="header">
			Edit Content: '.searchContentFor(get('id'), 'title').'
			</div>
			<div id="formDiv">
			<form method="POST" action="widget.php?id='.get('id').'&page=content&pages='.get('pages').$source.'" onsubmit="'.jsConfirm('Are you sure you want to continue saving this entry? This action cannot be undone.').'">
			Title: <input type="hidden" name="updateNow" value="'.get('id').'" />
			<input type="text" name="title" value="'.searchContentFor(get('id'), 'title').'" id="titleForm"/>
			</div>
			'.textEditor('contentEditor', 'contentText', searchContentFor(get('id'), 'contdata'), 'Save').'</form>'.
			$buttonDelete.'&nbsp;<input type="button" class="buttons" title="'.$linkBack.'" value="Close" onclick="'.jsClose().'" />
			
		</div>
		';
	}
	return $stuff;;
}
?>